package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.GroupBuyingMapper;
import com.ruoyi.system.domain.GroupBuying;
import com.ruoyi.system.service.IGroupBuyingService;

/**
 * 优惠团购Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-18
 */
@Service
public class GroupBuyingServiceImpl implements IGroupBuyingService
{
    @Autowired
    private GroupBuyingMapper groupBuyingMapper;

    /**
     * 查询优惠团购
     *
     * @param id 优惠团购主键
     * @return 优惠团购
     */
    @Override
    public GroupBuying selectGroupBuyingById(Long id)
    {
        // 每次点击修改阅读数量
        GroupBuying groupBuying = groupBuyingMapper.selectGroupBuyingById(id);
        if (groupBuying != null){
            groupBuying.setNum(groupBuying.getNum() + 1);
            groupBuyingMapper.updateGroupBuying(groupBuying);
        }
        return groupBuying;
    }

    /**
     * 查询优惠团购列表
     *
     * @param groupBuying 优惠团购
     * @return 优惠团购
     */
    @Override
    public List<GroupBuying> selectGroupBuyingList(GroupBuying groupBuying)
    {
        return groupBuyingMapper.selectGroupBuyingList(groupBuying);
    }

    @Override
    public List<GroupBuying> selectGroupBuyingHotList(GroupBuying groupBuying) {
        return groupBuyingMapper.selectGroupBuyingHotList(groupBuying);
    }

    /**
     * 新增优惠团购
     *
     * @param groupBuying 优惠团购
     * @return 结果
     */
    @Override
    public int insertGroupBuying(GroupBuying groupBuying)
    {
        return groupBuyingMapper.insertGroupBuying(groupBuying);
    }

    /**
     * 修改优惠团购
     *
     * @param groupBuying 优惠团购
     * @return 结果
     */
    @Override
    public int updateGroupBuying(GroupBuying groupBuying)
    {
        return groupBuyingMapper.updateGroupBuying(groupBuying);
    }

    /**
     * 批量删除优惠团购
     *
     * @param ids 需要删除的优惠团购主键
     * @return 结果
     */
    @Override
    public int deleteGroupBuyingByIds(Long[] ids)
    {
        return groupBuyingMapper.deleteGroupBuyingByIds(ids);
    }

    /**
     * 删除优惠团购信息
     *
     * @param id 优惠团购主键
     * @return 结果
     */
    @Override
    public int deleteGroupBuyingById(Long id)
    {
        return groupBuyingMapper.deleteGroupBuyingById(id);
    }
}
